﻿@using NetSurveillance.WebApp.Models
@model NetSurveillance.WebApp.DataServices.Models.MonitorSetting
@{
    ViewBag.Title = Resources.MenuResource.SystemSetting_MonitorSetting;
    Layout = "~/Views/Shared/_SystemConfigLayout.cshtml";
    ViewBag.CurrentMiddleMenu = 1;
    ViewBag.CurrentMainMenu = 5;
    string protocolSelectStr = ViewData["protocol"] as string;
    var supportProtocols = ViewBag.SupportProtocols as IList<SupportProtocol>;
}
@using (Html.BeginForm())
{
    @Html.ValidationSummary()
    <div id="main_content">
        <div class="config_top">
            <dl class="config_top_menu">
                <dd class="nowselect">监控参数设置</dd>
                @*<dd>监控模式设置</dd>*@
                <dd>网页浏览文件保存设置</dd>
            </dl>
        </div>
        <div class="config_content0">
            <dl id="paradl0">
                @foreach (var protocol in supportProtocols)
                {
                    <dd>
                        <label>
                        @Html.CheckBox("protocols", protocol.Name as string, !string.IsNullOrWhiteSpace(protocolSelectStr) && protocolSelectStr.Contains(protocol.Name))
                        @protocol.DisplayText
                        </label>
                    </dd>
                }
            </dl>
            @*<dl id="paradl1">
                <dt>
                    <label>@Html.RadioButtonFor(m => m.MonitorType, 1)Mac监控模式</label>
                </dt>
                <dt>
                    <label>@Html.RadioButtonFor(m => m.MonitorType, 2)IP监控模式</label>
                </dt>
                <dd>说明:一般情况下,建议使用基于网卡MAC地址监控模式,如遇到VLAN或路由等无法被监控机MAC情况下,可使用基于IP的监控方式</dd>
            </dl>*@
            <dl id="paradl2">
                <dd>
                    <div class="leftdiv">是否保存浏览网页内容</div>
                    <label>
                        @Html.RadioButtonFor(m => m.IsSaveWebContent, true, new { id = "isSaveWebContent_Yes" }) 是
                    </label>
                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    <label>
                        @Html.RadioButtonFor(m => m.IsSaveWebContent, false, new { id = "isSaveWebContent_No" }) 否
                    </label>
                </dd>
                <dd>
                    <div class="leftdiv">保存网页文件大小(min-max)</div>
                    @Html.TextBoxFor(m => m.MinSize)字节- @Html.TextBoxFor(m => m.MaxSize)字节</dd>
                <dd>
                    <div class="leftdiv">保存网页格式类型(使用","号分割)</div>
                    @Html.TextBoxFor(m => m.SaveFileExts)</dd>
                <dd style="display: none;">
                    <div class="leftdiv">文件自动删除时间</div>
                    @Html.TextBoxFor(m => m.SaveFileDay)
                    天前
                </dd>
            </dl>
        </div>

    </div>
    <div>
        @Html.HiddenFor(m => m.DefaultPageSize)
        @Html.Hidden("Id")
        <ul class="config_bottom_btndivs">
            <li>
                <input type="button" id="btnSaveQuery" value="@Resources.Resource.Button_Apply"/>
            </li>
            <li>
                <input type="reset" id="btnResetChanges" value="@Resources.Resource.Button_ResetChanges"/>
            </li>
        </ul>
    </div>
}
@section javascript{
    <script type="text/javascript">
        $(function () {
            pageResize();
            $(window).bind('resize', pageResize);
            $(".config_top_menu dd").each(function (i) {
                $(this).click(function () {
                    $(".config_top_menu dd").removeClass("nowselect");
                    $(this).addClass("nowselect");
                    $(".config_content0 dl").hide();
                    $('.config_content0 dl:eq(' + i + ')').show();
                });
            });
            $('#btnSaveQuery').click(function () {
                if ($('form').valid() && validForm())
                    document.forms[0].submit();
            });
            $('#isSaveWebContent_Yes,#isSaveWebContent_No').click(checkIsSaveWebContent);
            checkIsSaveWebContent();
        });
        
        function pageResize() {
            var arrayPageSize = getPageSize();
            var myHeight = arrayPageSize[3];
            $("#main_content").height(myHeight - 191);
        }

        function checkIsSaveWebContent() {
            var isNoCheck = $('#isSaveWebContent_No').is(':checked'),
                $eles = $('#isSaveWebContent_No').closest('dd').siblings().find(':input');
            if (isNoCheck)
                $eles.attr('disabled', true);
            else
                $eles.removeAttr('disabled');
        }

        function validForm() {
            var $minSize = $('#MinSize'),
                $maxSize = $('#MaxSize'),
                minSize = parseInt($minSize.val()),
                maxSize = parseInt($maxSize.val());
            if (minSize < 0 || maxSize > 10000) {
                alert('网页保存最小值区间为0-10000，这两个值不可在此区间外');
                return false;
            }
            if (minSize > maxSize) {
                alert('网页保存最小值必须小于最大值');
                return false;
            }
            return true;
        }
    </script>
}